//
//  Copyright (c) 2014-2016 Actor LLC. <https://actor.im>
//

import Foundation

let frameworkBundle = NSBundle(identifier: "im.actor.ActorSDK")!

public extension NSBundle {
    static var framework: NSBundle {
        get {
            return frameworkBundle
        }
    }
}

public extension UIImage {
    class func bundled(named: String) -> UIImage? {
        
        if let appImage = UIImage(named: named) {
            return appImage
        }
        if #available(iOS 8.0, *) {
            return UIImage(named: named, inBundle: NSBundle.framework, compatibleWithTraitCollection: UITraitCollection(displayScale: UIScreen.mainScreen().scale))
        } else {
            // Fallback on earlier versions
//            fatalError("*** iOS 8x API")
            let resourcePath = NSBundle.framework.resourcePath
            if resourcePath != nil {
                if let image = UIImage(contentsOfFile: resourcePath! + "/" + named) {
                    print("image:->\(image)\n path:->\(resourcePath!)/\(named)")
                    return image
                }
                print("image path:->\(resourcePath!)")
            }
            
            return UIImage()
        }
    }
}